home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1997-01-28 | 4.6 KB | 174 lines |
- 10 'CUSTOHM - 10 AUG 92 rev. 27 SEP 96
- 20 IF EX$=""THEN EX$="EXIT"
- 30 CLS:KEY OFF
- 40 COLOR 7,0,1
- 50 UL$=STRING$(80,205)
- 60 U$="##,###"
- 70 U1$="##"
- 80 U2$="#####,###.##"
- 90 U3$="#####.#"
- 100 U4$="####.#"
- 110 O$=CHR$(234) 'omega
- 120 DIM Q(20,3) 'quantity,value,net resistance
- 130 DIM R(24) '24 combinations
- 140 DIM C$(10) 'colour codes
- 150 '.....standard 5% resistors
- 160 DATA 1,1.1,1.2,1.3,1.5,1.6,1.8,2.0,2.2,2.4,2.7,3
- 170 DATA 3.3,3.6,3.9,4.3,4.7,5.1,5.6,6.2,6.8,7.5,8.2,9.1
- 180 FOR Z=1 TO 24
- 190 READ R(Z)
- 200 NEXT Z
- 210 '.....colour codes
- 220 DATA Blk,Brn,Red,Orn,Yel,Grn,Blu,Vio,Gry,Wht
- 230 FOR Z=O TO 9
- 240 READ C$(Z)
- 250 NEXT Z
- 260 '
- 270 '.....menu
- 280 CLS
- 290 COLOR 15,2
- 300 PRINT " RESISTORS in PARALLEL";TAB(57);"by George Murphy VE3ERP ";
- 310 COLOR 1,0:PRINT STRING$(80,223);
- 320 COLOR 7,0
- 330 T=8 'tab for text
- 340 GOSUB 1220
- 350 COLOR 0,7:LOCATE CSRLIN+1,22
- 360 PRINT " Press 1 to continue or 0 to EXIT....."
- 370 COLOR 7,0
- 380 Z$=INKEY$:IF Z$=""THEN 380
- 390 IF Z$="0"THEN CLS:RUN EX$
- 400 IF Z$="1"THEN 420
- 410 GOTO 380
- 420 VIEW PRINT 3 TO 24:CLS:VIEW PRINT:LOCATE 3
- 430 '
- 440 INPUT " ENTER: Value of custom resistor (ohms).......";RC
- 450 LOCATE CSRLIN-1
- 460 '
- 470 '.....calculate resistor banks
- 480 N=0
- 490 FOR Y=1 TO 10 'no. of resistors loop
- 500 RX=RC*Y 'value of resistor
- 510 M=1 'multiplier
- 520 FOR Z=1 TO 24
- 530 IF R(Z)*M>RX THEN 580
- 540 NEXT Z
- 550 M=M*10
- 560 GOTO 520
- 570 '
- 580 R1=R(Z-1)*M 'next lower resistor
- 590 IF Z=1 THEN R1=R(12)*M/10
- 600 N=N+1 'counter
- 610 Q(N,1)=Y 'quantity of resistors in bank
- 620 Q(N,2)=R1 'value of each resistor
- 630 Q(N,3)=R1/Y 'net resistance of resistor bank
- 640 '
- 650 R2=R(Z)*M 'next higher resistor
- 660 N=N+1 'counter
- 670 Q(N,1)=Y 'quantity of resistors in bank
- 680 Q(N,2)=R2 'value of each resistor
- 690 Q(N,3)=R2/Y 'net resistance of resistor bank
- 700 NEXT Y
- 710 '
- 720 '******START SORT******
- 730 SN=N
- 740 SM=SN
- 750 SM=INT(SM/2):IF SM=0 THEN 840
- 760 SK=SN-SM:SJ=1
- 770 SI=SJ
- 780 SL=SI+SM
- 790 IF Q(SI,3)<=Q(SL,3)THEN 820
- 800 FOR A=1 TO 3:SWAP Q(SI,A),Q(SL,A):NEXT A
- 810 SI=SI-SM:IF SI>0 THEN 780
- 820 SJ=SJ+1:IF SJ>SK THEN 750
- 830 GOTO 770
- 840 '******SORT COMPLETED******
- 850 '
- 860 '....display data
- 870 VIEW PRINT 3 TO 24:CLS:VIEW PRINT:LOCATE 3
- 880 FOR Z=1 TO N
- 890 PC=ABS(Q(Z,3)-RC)/RC*100 '% off target
- 900 IF Q(Z,1)=1 THEN P$=STRING$(13,32)+"="ELSE P$=" in parallel ="
- 910 IF Q(Z-1,3)<=RC AND Q(Z,3)>RC THEN GOSUB 1480
- 920 IF PC<=5 THEN COLOR 15,2 ELSE COLOR 7,0
- 930 PRINT TAB(3);
- 940 PRINT USING U1$;Q(Z,1); 'print quantity
- 950 R=Q(Z,2):V$=O$ 'value
- 960 R$=STR$(R)
- 970 L$=STR$(LEN(R$)-3)
- 980 Q$=LEFT$(R$,2):GOSUB 1160:C1$=C$
- 990 Q$=MID$(R$,3,1):GOSUB 1160:C2$=C$
- 1000 Q$=LEFT$(L$,2):GOSUB 1160:C3$=C$
- 1010 CC$=C1$+"/"+C2$+"/"+C3$
- 1020 IF R>=10000 THEN R=R/1000:V$="K"
- 1030 IF R<10 THEN X$=U4$ ELSE X$=U$
- 1040 PRINT" @";USING X$;R; 'print value
- 1050 PRINT " ";V$;P$;
- 1060 PRINT USING U2$;Q(Z,3);:PRINT " ";O$; 'print net resistance of bank
- 1070 IF Q(Z,3)=RC THEN PRINT " ON TARGET !";:GOTO 1090
- 1080 PRINT USING U3$;PC;:PRINT " % off target"; 'discrepancy
- 1090 IF R<10 THEN CC$=" - "
- 1100 PRINT TAB(68);CC$
- 1110 NEXT Z
- 1120 PRINT UL$;
- 1130 GOSUB 1610 'screen dump
- 1140 GOTO 270
- 1150 '
- 1160 '.....calculate colour code
- 1170 FOR CC=0 TO 9
- 1180 IF CC=VAL(Q$)THEN C$=C$(CC):GOTO 1200
- 1190 NEXT CC
- 1200 RETURN
- 1210 '
- 1220 '.....text page
- 1230 PRINT TAB(T);
- 1240 PRINT "This program designs custom resistors that will be very close to"
- 1250 PRINT TAB(T);
- 1260 PRINT "almost any reasonable value, using standard common resistors"
- 1270 PRINT TAB(T);
- 1280 PRINT "connected in parallel."
- 1290 PRINT
- 1300 PRINT TAB(T);
- 1310 PRINT "The program calculates several combinations of resistors, any of"
- 1320 PRINT TAB(T);
- 1330 PRINT "which will provide a net resistance close to your target value."
- 1340 PRINT
- 1350 PRINT TAB(T);
- 1360 PRINT "Each combination displayed shows what percentage it is off the"
- 1370 PRINT TAB(T);
- 1380 PRINT "target resistance. Combinations within 5% of the target value"
- 1390 PRINT TAB(T);
- 1400 PRINT "are high-lighted."
- 1410 PRINT
- 1420 PRINT TAB(T);
- 1430 PRINT "Just enter the value of the custom resistor you want and the"
- 1440 PRINT TAB(T);
- 1450 PRINT "computer will do the rest !"
- 1460 RETURN
- 1470 '
- 1480 '.....hi-lite sought resistance
- 1490 COLOR 14,4
- 1500 PRINT " TARGET RESISTANCE";
- 1510 PRINT STRING$(11,".");USING U2$;RC;
- 1520 PRINT " ";O$;
- 1530 FOR L=1 TO 80
- 1540 Y=SCREEN(CSRLIN,L)
- 1550 IF Y=234 THEN 1570
- 1560 NEXT L
- 1570 PRINT STRING$(78-L,32);
- 1580 COLOR 7,0
- 1590 RETURN
- 1600 '
- 1610 'HARDCOPY
- 1620 GOSUB 1730:LOCATE 25,2:COLOR 14,6
- 1630 PRINT " Press 1 to print screen, 2 to print screen & ";
- 1640 PRINT "advance paper, or 3 to continue.";:COLOR 7,0
- 1650 Z$=INKEY$:IF Z$="3"THEN GOSUB 1730:RETURN
- 1660 IF Z$="1"OR Z$="2"THEN GOSUB 1730:GOTO 1680
- 1670 GOTO 1650
- 1680 FOR QX=1 TO 24:FOR QY=1 TO 80
- 1690 LPRINT CHR$(SCREEN(QX,QY));
- 1700 NEXT QY:NEXT QX
- 1710 IF Z$="2"THEN LPRINT CHR$(12)
- 1720 GOTO 1620
- 1730 LOCATE 25,1:PRINT STRING$(80,32);:RETURN
-